#ifndef LOGICDIO_H
#define LOGICDIO_H

#include "LogicPool/LogicPool.h"

class LogicDIO : public LogicPool 
{

  protected:
	
	bool isNIM;
	bool termination;

    void SetMode()
    {
        uint8_t data = (isNIM ? 2 : 0) + (termination ? 1 : 0);
        SetMode(data);
    };

  public:

    LogicDIO(LogicInterface & iinterface, uint8_t number = 1) 
        : LogicPool(iinterface, 'T', number), isNIM(false), termination(false) {};

    LogicDIO(LogicInterface & iinterface, uint8_t number, bool iisNIM) 
        : LogicPool(iinterface, 'T', number), termination(false) 
    {
    	if (iisNIM) SetNIM();
    };

    void SetDebounce(uint8_t milliseconds) 
    {
        SetAddress(1);
        logicpool.WriteByte(milliseconds);
    };

    void SetMode(uint8_t mode)
    {
        //cout << "mode: " << (int) mode << endl;
        SetAddress(2);
        logicpool.WriteByte(mode);
    };

    void SetTermination(bool enabled = true) 
    {
    	termination = enabled;
        SetMode();
    };

    void SetTTL() 
    {
        isNIM = false;
        SetMode();
    };

	void SetNIM()
    {
        isNIM = true;
        SetMode();
    };

	bool IsNIM()
	{
		return isNIM;
	};

	bool GetState()
    {
        SetAddress(1);
        return logicpool.ReadBool();
    };

};

#endif
